import ServiceBase from '../base';
import {MemberPageProxy} from '../proxies/member-model-list-proxy';
import {MemberModelProxy} from '../proxies/member-model-proxy';
import * as proxy from '../proxy';

const ACCOUNTS = '/accounts';
const GROUPS = '/groups';

class MemberService extends ServiceBase {
    getAllAccountMembers = (accountId) => {
        let promise = super.get({
            url: ACCOUNTS + `/${accountId}/members`,
        });
        return proxy.httpResultProxy(promise, MemberPageProxy);
    };
    // accounts
    getMembersPaging = (data) => {
        let promise = super.get({
            url: ACCOUNTS + `/${data.accountId}/members`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise, MemberPageProxy);
    };
    getMembersUnGroupPaging = (data) => {
        let promise = super.get({
            url: `${ACCOUNTS}/${data.accountId}${GROUPS}/members/ungrouped`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise, MemberPageProxy);
    };
    getMembersGroupPaging = (data) => {
        let promise = super.get({
            url: ACCOUNTS + `/${data.accountId}${GROUPS}/${data.groupId}/members`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise, MemberPageProxy);
    };
    getMeAccountMemberAction = (accountId) => {
        let promise = super.get({
            url: ACCOUNTS + `/${accountId}/members/me/info`,
        });
        return proxy.httpResultProxy(promise, MemberModelProxy);
    };
    shiftAccountMemberActive = (data) => {
        let promise = super.put({
            url: ACCOUNTS + `/${data.accountId}/members/${data.memberId}/state`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, MemberModelProxy);
    };

    // changeMemberRoles = (data) => {
    //   let promise = super.put(ACCOUNTS + `/${data.accountId}/members/${data.memberId}/roles`, data.data);
    //   return proxy.httpResultProxy(promise, MemberModelProxy);
    // };
    updateAccountMemberRole = (data) => {
        let promise = super.post({
            url: ACCOUNTS + `/${data.accountId}/userRoles/batch`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, MemberModelProxy);
    };

    addMemberToAccount = (data) => {
        let promise = super.post({
            url: ACCOUNTS + `/${data.accountId}/members`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, MemberPageProxy);
    };
    getAccountMemberByMemberId = (data) => {
        let promise = super.get({
            url: ACCOUNTS + `/${data.accountId}/members/${data.memberId}`,
        });
        return proxy.httpResultProxy(promise, MemberModelProxy);
    };
    searchAccountMember = (data) => {
        let promise = super.get({
            url: ACCOUNTS + `/${data.accountId}/members/search`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise, MemberModelProxy);
    };
    deleteAccountMember = (data) => {
        let promise = super.delete({
            url: ACCOUNTS + `/${data.accountId}/members/${data.memberId}`,
        });
        return proxy.httpResultProxy(promise, MemberModelProxy);
    };
    // POST /accounts/{accountId}/emails/check/batch批量检查邮箱在系统中的类型
    public checkMembersEmail = (data) => {
        let promise = super.post({
            url: `${ACCOUNTS}/${data.accountId}/emails/check/batch`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // POST /accounts/{accountId}/members/batch批量创建组织成员
    public addMultiplyUserByExcel = (data) => {
        let promise = super.post({
            url: `${ACCOUNTS}/${data.accountId}/members/batch`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // PUT /accounts/{accountId}/members/batch批量修改组织成员
    public updateAccountMembers = (data) => {
        let promise = super.put({
            url: `${ACCOUNTS}/${data.accountId}/members/batch`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // projects
    getProjectMember = (data) => {
        let promise = super.get({
            url: ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/members`,
        });
        return proxy.httpResultProxy(promise, MemberPageProxy);
    };
    getProjectMemberOfMe = (data) => {
        let promise = super.get({
            url: ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/members/me/info`,
        });
        return proxy.httpResultProxy(promise, MemberModelProxy);
    };
    isMeJoinedProject = (data) => {
        let promise = super.get({
            url: ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/members/me`,
        });
        return proxy.httpResultProxy(promise);
    };
    postMember = (data) => {
        let promise = super.post({
            url: ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/members`,
            data: data.memberNames,
        });
        return proxy.httpResultProxy(promise, MemberPageProxy);
    };
    public addMultiplyProjectUserByExcel = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/members/batch`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, MemberPageProxy);
    };
    public updateProjectMemberRole = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/userRoles/batch`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    deleteMember = (data) => {
        let promise = super.delete({
            url: ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/members/${data.memberId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    // DELETE /accounts/{accountId}/projects/{projectId}/members/batch 批量删除项目成员
    deleteMemberBatch = (data) => {
        let promise = super.delete({
            url: ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/members/batch`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    postMemberAdmin = (data) => {
        let promise = super.put({
            url: ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/members/${data.id}/roles`,
            data: {
                roleNames: data.roleNames,
            },
        });
        return proxy.httpResultProxy(promise, MemberModelProxy);
    };
    getMemberInfo = (data) => {
        let promise = super.get({
            url: ACCOUNTS + `/${data.accountId}/projects/${data.projectId}/members/${data.id}`,
        });
        return proxy.httpResultProxy(promise);
    };
    resetUserPassword = (data) => {
        let promise = super.put({
            url: ACCOUNTS + `/${data.accountId}/members/${data.memberId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
}

export {MemberService};
